home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 056 (1988-05-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 056 (1988-05-15)(Ossowski, Stefan)(DE)(PD).adf / WFrags / WFrags.c < prev    next >
C/C++ Source or Header  |  1988-04-13  |  5KB  |  187 lines

  1. /*
  2.  *   This program displays a constantly-updating window indicated your
  3.  *   memory fragmentation, free memory, and sizes of the largest
  4.  *   available chunks.  Useful for finding out why those large programs
  5.  *   won't load.  Also useful during development to see what impact
  6.  *   your application is having on memory fragmentation.
  7.  *
  8.  *   To run, simply type
  9.  *
  10.  *      run wfrags
  11.  *
  12.  *   That's all!  Enjoy this program.  Bugs to Tomas Rokicki, Box 2081,
  13.  *   Stanford, CA  94309.
  14.  */
  15. #include "intuition/intuition.h"
  16. #include "functions.h"
  17. #include <exec/exec.h>
  18. #include <exec/execbase.h>
  19. long delayval = 40 ;
  20. struct Window *window ;
  21. struct MsgPort *myport ;
  22. struct IntuitionBase *IntuitionBase ;
  23. struct NewWindow newwindow = {
  24.    0,                                        /* left edge */
  25.    0,                                        /* top edge */
  26.    544,                                      /* width */
  27.    46,                                       /* height */
  28.    0,                                        /* detail pen */
  29.    1,                                        /* block pen */
  30.    CLOSEWINDOW,                              /* these messages we receive. */
  31.    WINDOWDEPTH | WINDOWCLOSE | WINDOWDRAG | SMART_REFRESH,
  32.                                              /* a few gadgets */
  33.    NULL,                                     /* no gadgets initially */
  34.    NULL,                                     /* default checkmark */
  35.    (UBYTE *)"Wfrags (by Radical Eye Software)",  /* title */
  36.    NULL,                                     /* initialize this! */
  37.    NULL,                                     /* use screen bitmap */
  38.    -1, -1, -1, -1,                           /* min sizes */
  39.    WBENCHSCREEN } ;                          /* this is a customscreen */
  40. long chip[25], fast[25] ;
  41. char buf[80] ;
  42. struct TextAttr myfont = {
  43.    (STRPTR) "topaz.font",
  44.    TOPAZ_EIGHTY,
  45.    0,
  46.    0
  47. };
  48. struct IntuiText intuitext = {
  49.    1, 0,
  50.    JAM2,
  51.    0, 0,
  52.    &myfont,
  53.    (UBYTE *)buf,
  54.    NULL
  55. };
  56. draw(where)
  57. long where ;
  58. {
  59.    PrintIText(window->RPort, &intuitext, 4L, where) ;
  60. }
  61. static char tbuf[8] ;
  62. icat(i, s)
  63. long i ;
  64. register char *s ;
  65. {
  66.    register char *p, *q ;
  67.  
  68.    p = tbuf ;
  69.    do {
  70.       *p++ = '0' + i % 10 ;
  71.       i = i / 10 ;
  72.    } while (i) ;
  73.    q = buf + strlen(buf) ;
  74.    while (p > tbuf)
  75.       *q++ = *--p ;
  76.    strcpy(q, s) ;
  77. }
  78. fillout(s, i)
  79. char *s ;
  80. register long *i ;
  81. {
  82.    register char *p ;
  83.    int j ;
  84.  
  85.    strcpy(buf, s) ;
  86.    p = buf + strlen(buf) ;
  87.    i += 3 ;
  88.    for (j=0; j<21; j++, i++, p += 3) {
  89.       if (*i == 0)
  90.          p[2] = ' ' ;
  91.       else
  92.          p[2] = '0' + *i % 10 ;
  93.       if (*i < 10)
  94.          p[1] = ' ' ;
  95.       else
  96.          p[1] = '0' + (*i / 10) % 10 ;
  97.       if (*i < 100)
  98.          *p = ' ' ;
  99.       else
  100.          *p = '0' + *i / 100 ;
  101.    }
  102.    *p = 0 ;
  103. }
  104. updatescreen() {
  105.    register long size ;
  106.    register long i ;
  107.    register struct MemHeader *hdr ;
  108.    register struct MemChunk *chunk ;
  109.    extern struct ExecBase *SysBase ;
  110.    register long *which ;
  111.  
  112.    for (i=0; i<25; i++) {
  113.       chip[i] = 0 ;
  114.       fast[i] = 0 ;
  115.    }
  116.    Forbid() ;
  117.    hdr = (struct MemHeader *) SysBase->MemList.lh_Head ;
  118.    while (hdr->mh_Node.ln_Succ) {
  119.       if (hdr->mh_Attributes & MEMF_CHIP)
  120.          which = chip ;
  121.       else
  122.          which = fast ;
  123.       for (chunk = hdr->mh_First; chunk; chunk = chunk->mc_Next) {
  124.          size = chunk->mc_Bytes ;
  125.          *which += size ;
  126.          if (size > which[1])
  127.             which[1] = size ;
  128.          i = 0 ;
  129.          if (size >= 0x10000) {
  130.             size >>= 16 ;
  131.             i += 16 ;
  132.          }
  133.          if (size >= 0x100) {
  134.             size >>= 8 ;
  135.             i += 8 ;
  136.          }
  137.          if (size >= 0x10) {
  138.             size >>= 4 ;
  139.             i += 4 ;
  140.          }
  141.          if (size >= 4) {
  142.             size >>= 2 ;
  143.             i += 2 ;
  144.          }
  145.          if (size >= 2) {
  146.             size >>= 1 ;
  147.             i += 1 ;
  148.          }
  149.          which[i]++ ;
  150.       }
  151.       hdr = (struct MemHeader *)hdr->mh_Node.ln_Succ ;
  152.    }
  153.    Permit() ;
  154.    strcpy(buf,
  155.    "      3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23") ;
  156.    draw(11L) ;
  157.    fillout("chip", chip) ;
  158.    draw(19L) ;
  159.    fillout("fast", fast) ;
  160.    draw(27L) ;
  161.    strcpy(buf, "(Chip tot=") ;
  162.    icat(chip[0], " big=") ;
  163.    icat(chip[1], ") (Fast tot=") ;
  164.    icat(fast[0], " big=") ;
  165.    icat(fast[1], ")     ") ;
  166.    draw(35L) ;
  167. }
  168. main() {
  169.    struct IntuiMessage *message ;
  170.  
  171.    if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary(
  172.          "intuition.library",33L))!=NULL &&
  173.          (window=OpenWindow(&newwindow))!=NULL) {
  174.       while ((message=(struct IntuiMessage *)GetMsg(window->UserPort))
  175.               ==NULL) {
  176.          updatescreen() ;
  177.          Delay(delayval) ;
  178.       }
  179.    }
  180.    if (window)
  181.       CloseWindow(window) ;
  182.    if (IntuitionBase)
  183.       CloseLibrary(IntuitionBase) ;
  184. }
  185. _cli_parse() {}
  186. _wb_parse() {}
  187.